package com.example.mylearn.thread;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.jupiter.api.Test;

import java.util.LinkedList;

public class TreeReview {

    @NoArgsConstructor
    @Data
    @AllArgsConstructor
    private static class Node<T>{
        T data;
        Node<T> left;
        Node<T> right;

        public Node(T data) {
            this.data = data;
        }
    }


    public <T> void preOrder(Node<T> root) {
        if (null != root) {
            System.out.print(root.data);
            preOrder(root.left);
            preOrder(root.right);
        }
    }

    public <T> void inOrder(Node<T> root) {
        if (null != root) {
            inOrder(root.left);
            System.out.print(root.data);
            inOrder(root.right);
        }
    }


    public <T> void postOrder(Node<T> root) {
        if (null != root) {

            postOrder(root.left);
            postOrder(root.right);
            System.out.print(root.data);

        }
    }



    @Test
    public void testTree() {
        Node<String> root = new Node<String>();
        root.data = "A";
        root.left = new Node<>("B");
        root.right = new Node<>("C");

        root.left.left = new Node<>("D");
        root.left.right = new Node<>("E");

        root.right.left = new Node<>("F");
        root.right.right = new Node<>("G");

        root.left.left.left = new Node<>("H");


        preOrder(root);
        System.out.println();
        inOrder(root);
        System.out.println();
        postOrder(root);
    }
















}
